<!-- 商品列表组件 -->
<template>
    <div>
      <h2>商品列表</h2>
      <ul>
        <li v-for="item in items" :key="item.id">
          {{ item.name }} - ￥{{ item.price }}
          <button @click="addToCart(item)">添加到购物车</button>
        </li>
      </ul>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        items: [
          { id: 1, name: '商品1', price: 100 },
          { id: 2, name: '商品2', price: 200 },
          { id: 3, name: '商品3', price: 300 }
        ]
      }
    },
    methods: {
      addToCart(item) {
        this.$store.commit('addToCart', item)
      }
    }
  }
  </script>